package link;

import java.util.*;

public class ReceivedBuffer {

	// The received message buffer used
	// in this class as a queue
	public LinkedList<String> receiveBuffer;

	public ReceivedBuffer() {
		receiveBuffer = new LinkedList<String>();
	}

	public boolean isEmpty() {
		return receiveBuffer.isEmpty();
	}

	public String receive() {
		try {
			String s = receiveBuffer.removeLast();

			// Some messages are skipped if the thread
			// is not busy (or doesn't fall asleep).
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				System.out.println(e);
				System.exit(0);
			}

			return s;
		} catch (NoSuchElementException e) {
			return null;
		}
	}

}